package com.xpgk.mvc.bstockHandover;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jfinal.aop.Before;
import com.jfinal.plugin.activerecord.tx.Tx;
import com.xpgk.mvc.base.BaseController;
import com.xpgk.mvc.codeSet.Code;

public class BstockHandoverController extends  BaseController{
	
	private BstockHandoverService  bstockHandoverService;
	public  void  index()
	{	
    	String  organids=getCUserOrganIds();
    	String  userids=getCUserIds();
    	setAttr("organids", organids);
		setAttr("userids", userids);
		setAttr("lcIds",Code.lc_ids);
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("column", StockHandover.column_organIds);
		String sql = getSqlByBeetl(StockHandover.sqlId_column, param);
		List<StockHandover> shList = StockHandover.dao.find(sql,organids);
		if(shList!=null && shList.size()>0)
		{
			setAttr("stockHandover", shList.get(0));
		}
		render("BstockHandover.html");
	}
	/**查询库存交接
	 * 
	 */
	public  void  getStock()
	{	
		String json = paging(splitPage, StockTransfer.sqlId_splitPageSelect, StockTransfer.sqlId_splitPageFrom);
		renderJson(json);
//		String orgids=getCUserOrganIds();
//		String  kcjjList=bstockHandoverService.getStock(orgids);
//		renderJson(kcjjList);
	}
	public  void  verifyPassword()
	{
		String  userIds=getPara("userIds");
		String  password=getPara("password");
		String msg=bstockHandoverService.verifyPassword(userIds,password);
		renderText(msg);
	}
	
	
	/**保存库存交接
	 * 
	 */
	@Before(Tx.class)
	public  void  saveStockHandover()
	{
		List<StockTransfer> stList = getModels(StockTransfer.class);
		StockHandover  sh=getModel(StockHandover.class);
		String orgids=getCUserOrganIds();
		String msg=bstockHandoverService.saveStockHandover(orgids,sh,stList);
		renderText(msg);
		
	}
}
